<?php

/**
 * @author christian
 * @copyright 2011
 *  
 */
 

 //establecer una variable conratafisica $_LOCALHOST
$ruta=$_SERVER['DOCUMENT_ROOT']."/viventura"."/MDCostos";
include_once("$ruta/star.php");
//include_once("$rut/conf/CConfig.php");



if (!isset($_POST['multi'])) {$_POST['multi'] = "NULL"; }
if (!isset($_POST['default'])) {$_POST['default'] = "NULL"; }
if (!isset($_POST['idPack'])) {$_POST['idPack'] = "NULL"; }
if (!isset($_POST['idTour'])) {$_POST['idTour'] = "NULL"; }
if (!isset($_POST['idPackTour'])) {$_POST['idPackTour'] = "NULL"; }
if (!isset($_POST['idOpe'])) {$_POST['idOpe'] = "NULL"; }


$multiple = $_POST['multi'];
$default=$_POST['default'];
$idPack=$_POST['idPack'];
$idTour=$_POST['idTour'];
$idPackTour=$_POST['idPackTour'];
$idOpe=$_POST['idOpe'];


if($default==1){
    
        $query = "insert into tour (idTour) values ('NULL')";
        $idTourCopy = CModelo::getInstance()->insertData($query);
            
        $query = "insert into pack_has_tour (idPackTour,PACK_idPack,TOUR_idTour) values ('NULL', '$idPack','$idTourCopy')";
        $idPackTour = CModelo::getInstance()->insertData($query);
               
        //registrando extensiones
        if($multiple!="NULL"){
        foreach($multiple as $r=>$c){ 
            $query = "insert into pack_has_tour_has_extensiones (idExtTour,pack_has_tour_idPackTour,extensiones_idExt,operador_idOpe) values ('NULL','$idPackTour','$c','$idOpe')";
            $extension = CModelo::getInstance()->insertData($query);
        }}
                
         
        echo "<script> parent.location.href = 'MDPasajeros/MDPasajeros.php?codigo=$idPackTour' </script>";
    }

else{
     if($multiple=="NULL"){
        
        $query = "delete from pack_has_tour_has_extensiones where pack_has_tour_idPackTour=$idPackTour";
        CModelo::getInstance()->insertData($query);
             
    }
      else{
        $query = "delete from pack_has_tour_has_extensiones where pack_has_tour_idPackTour=$idPackTour";
        CModelo::getInstance()->insertData($query);
        echo $query;
        echo "gaojghnasg";   
    
              
        foreach($multiple as $r=>$c){ 
        
        $query = "insert into pack_has_tour_has_extensiones (idExtTour,pack_has_tour_idPackTour,extensiones_idExt,operador_idOpe) values ('NULL','$idPackTour','$c','$idOpe')";
        echo $query;
        $extension = CModelo::getInstance()->insertData($query);
        }
        
        echo "<script> parent.location.href = '/viventura/MDCostos/index.php?updated=$idPack' </script>";
       
    }
    
      
        
  
}
        
 
//include_once("$rut/elements/head.tpl");
include_once("$rut/elements/foot.tpl");







?>